<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="author" content="lijinbo" />
    <title>Document</title>
  </head>
  <body>
    我是子页面
    <button id="btn">子传给父</button>
    <ul id="box"></ul>
    <script>
      window.addEventListener('message', function (event) {
        console.log('子页面接收到信息', event.data)
        document.getElementById('box').innerHTML += `<li>${JSON.stringify(event.data)}</li>`
      })

      document.getElementById('btn').addEventListener('click', () => {
        parent.postMessage({ data: 'emit' })
      })
    </script>
  </body>
</html>
